package com.app.miwawa.cui.portal;

import org.apache.log4j.Logger;
import org.framework.common.cui.AbstractController;
import org.framework.common.ext.exception.CommonException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.app.miwawa.api.portal.service.bo.DashboardBo;
import com.app.miwawa.api.system.entity.view.Account;

@RestController
public class DashboardController extends AbstractController {

	private Logger log = Logger.getLogger(DashboardController.class);
	
	@Autowired
	private DashboardBo bo;
	
	// 顾问
	@RequestMapping(value="/{dbname}/dashboard/adviser")
	public Object adviser(@PathVariable final String dbname, @ModelAttribute final Account account) throws Exception{
		// 参数检查
		if (check(dbname)) return error("请检查数据源或参数绑定源。");
		
		try{
			// 注册数据源
			registerDataSource(dbname);
			
			return bo.adviser(account);
		} catch (Exception e) {
			e.printStackTrace();
			throw new CommonException(log, "首页台账查询失败！");
		}
	}
	
	// 老师
	@RequestMapping(value="/{dbname}/dashboard/teacher")
	public Object teacher(@PathVariable final String dbname, @ModelAttribute final Account account) throws Exception{
		// 参数检查
		if (check(dbname)) return error("请检查数据源或参数绑定源。");
		
		try{
			// 注册数据源
			registerDataSource(dbname);
			
			return bo.teacher(account,account.getParams());
		} catch (Exception e) {
			e.printStackTrace();
			throw new CommonException(log, "首页台账查询失败！");
		}
	}
	
	// 领导
	@RequestMapping(value="/{dbname}/dashboard/leaders")
	public Object leaders(@PathVariable final String dbname, @ModelAttribute final Account account) throws Exception{
		// 参数检查
		if (check(dbname)) return error("请检查数据源或参数绑定源。");
		
		try{
			// 注册数据源
			registerDataSource(dbname);
			
			return bo.leaders(account);
		} catch (Exception e) {
			e.printStackTrace();
			throw new CommonException(log, "首页台账查询失败！");
		}
	}
}
